<template>
  <c-dialog ref="dialog" :data="selData" single warn-text="自检资料审核" title="自检资料审核" @open="openHandle" @close="closeHandle">
    <c-list ref="form" :model="formData" :rules="formRules" label-width="100px">
      <c-list-item label="软装陈列任务号" :value="detail.softwearTaskCode" />
      <c-list-item label="所属门店" :value="detail.shopName" />
      <c-list-item label="装修任务号" :value="detail.decorationTaskCode" />
      <c-list-item prop="selfCheckingVerifyResult" label="审核结果">
        <el-select v-model="formData.selfCheckingVerifyResult" placeholder="审核结果" style="width:100%">
          <el-option label="同意" :value="1" />
          <el-option label="不同意" :value="0" />
        </el-select>
      </c-list-item>
      <c-list-item
        v-if="formData.selfCheckingVerifyResult"
        :rules="[{ required: formData.selfCheckingVerifyResult , message: '请选择预计到店陈列时间' }]"
        prop="estimateToStoreDisplayTime"
        label="预计到店陈列时间"
      >
        <el-date-picker
          v-model="formData.estimateToStoreDisplayTime "
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期"
          clearable
        />
      </c-list-item>
      <c-list-item
        :rules="[{ required:!formData.selfCheckingVerifyResult , message: '请填写自检审核备注' }]"
        prop="selfCheckingVerifyRemarks"
        label="自检审核备注"
      >
        <el-input v-model="formData.selfCheckingVerifyRemarks" type="textarea" />
      </c-list-item>
      <c-list-item label="附件">
        <import-file
          :data="fileList"
          :show-upload="false"
          :show-edit="false"
          :show-remove="false"
        />
      </c-list-item>
      <c-list-item>
        <div class="btn-container">
          <c-button @click="cancelHandle">取消</c-button>
          <c-button type="primary" @click="confirmHandle">确认</c-button>
        </div>
      </c-list-item>
    </c-list>
  </c-dialog>
</template>
<script>
import importFile from '@/components/importFile'
import { getShopAttachment } from '@/api/softDecorate'
// import { deleteBatch } from '@/api/common'
import { getDetail } from '@/api/softDecorate'
import { selfCheckAudit } from '@/api/softDecorate'
// import { postShopAttachmentBat, getShopAttachment } from '@/api/decorate'
export default {
  name: 'SelfCheckAudit',
  components: { importFile },
  props: {
    selData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      fileList: [],
      formData: {
        estimateToStoreDisplayTime: '',
        selfCheckingVerifyRemarks: '',
        selfCheckingVerifyResult: 1
      },
      formRules: {
      }
    }
  },
  computed: {
    detail() {
      return this.selData.length > 0 ? this.selData[0] : {}
    }
  },
  created() {
    setTimeout(() => {
      if (!this.detail.id) return
      getDetail(this.detail.id).then(res => {
        const { id,
          estimateToStoreDisplayTime,
          selfCheckingVerifyRemarks,
          selfCheckingVerifyResult } = res.data
        this.formData = { id,
          estimateToStoreDisplayTime,
          selfCheckingVerifyRemarks,
          selfCheckingVerifyResult }
      })
    }, 1000)
  },
  methods: {
    openHandle() {
      if (!this.detail.id) return
      getShopAttachment(this.detail.id).then(res => {
        this.fileList = res.data.records.filter(i => i.attachmentType === '自检资料审核' || i.attachmentType === '现场视频')
      })
    },
    closeHandle() {
      this.formData = {
        estimateToStoreDisplayTime: '',
        selfCheckingVerifyRemarks: '',
        selfCheckingVerifyResult: 1
      }
    },
    confirmHandle() {
      this.$refs.form.validate().then(() => {
        const data = {
          id: this.detail.id,
          estimateToStoreDisplayTime: this.formData.selfCheckingVerifyResult ? this.formData.estimateToStoreDisplayTime : undefined,
          selfCheckingVerifyRemarks: this.formData.selfCheckingVerifyRemarks,
          selfCheckingVerifyResult: this.formData.selfCheckingVerifyResult
        }
        selfCheckAudit(data).then(res => {
          this.$message.success('操作成功！')
          this.$emit('on-success')
          this.$refs.dialog.visible = false
        })
      })
    },
    cancelHandle() {
      this.$refs.dialog.visible = false
    }
  }
}
</script>
